﻿#include "MainWindow.h"

#include <QDebug>
#include <QFile>
#include <QFileDialog>

#include "./ui_MainWindow.h"
#include "xlsxdocument.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent),
      ui(new Ui::MainWindow) {
  ui->setupUi(this);

  
}

MainWindow::~MainWindow() {
  delete ui;
}

void MainWindow::on_btnStartConvert_clicked() {
  // 获得文件名字
  QString fileName{ui->lineSelectFile->text()};
  // 空白则去获取
  if (fileName.isEmpty()) {
    fileName = QFileDialog::getOpenFileName(this, "Select Excel file",
                                            QApplication::applicationDirPath(),
                                            "Excel(*.xlsx)");
    if (fileName.isEmpty()) {
      return;
    }
  } else {
    // 不存在文件则返回
    if (!QFile::exists(fileName)) {
      qWarning() << "file not exist:" << fileName;
      return;
    }
  }

  // 打开文件
  QXlsx::Document x{fileName};
  // 获得所有的sheet
  auto allSheets{x.sheetNames()};
  // 存入选择框
  ui->comboSheetName->addItems(allSheets);

  auto v = x.read("I8").toString();
  qDebug() << v;
}
